import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
// import { fileURLToPath, URL } from 'node:url'
import path,{resolve} from 'path'
import {createSvgIconsPlugin} from "vite-plugin-svg-icons";
import Icons from 'unplugin-icons/vite'
const pathSrc = resolve(__dirname, "src");


// https://vitejs.dev/config/
export default defineConfig({
    plugins: [vue(), {
        name: 'images',
        enforce: 'pre',
        apply: 'build',
        transform(code, id) {
            if (/.(png|jpe?g|gif|webp|svg)(\?.*)?$/.test(id)) {
                return `export default "${id}";`
            }
        },
    }, Icons({
        autoInstall: true,
    }),
        createSvgIconsPlugin({
            // 指定需要缓存的图标文件夹
            iconDirs: [resolve(pathSrc, "assets/icons")],
            // 指定symbolId格式
            symbolId: "icon-[dir]-[name]",
        })],
    server: {
        host: '0.0.0.0',
        port: 8000,
        proxy: {
            '/api': {
                target: 'http://122.51.217.103:8001/',//目标服务器地址
                changeOrigin: true,
                // rewrite: (path) => path.replace(/^\/api/, '')
            },
        }
    },
    resolve: {
        alias: {
            '@': path.resolve(__dirname, './src'),
            // '@': fileURLToPath(new URL('./src', import.meta.url)),
            // '@assets':path.resolve(__dirname,'./src/assets'),
            // '@public': path.resolve(__dirname, './public'),
            // '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
})
